*************************************************************************************************
*																								*
*						Flexible Wages, Bargaining, and The Gender Gap							*
*						Barbara Biasi and Heather Sarsons										*
*						Appendix Tables															*
*																								*
*************************************************************************************************

clear all
set more off
set matsize 11000
set maxvar 32000


global user = 2 // 1 = Heather, 2 = Barbara

if $user == 1 {
cd "/Users/sarsons/Dropbox/wisconsin_women/data"
global tab = "/Users/sarsons/Dropbox/wisconsin_women/draft/tables"
global out = "/Users/sarsons/Dropbox/wisconsin_women/out"
global do = "/Users/sarsons/Dropbox/wisconsin_women/do"
global RA = "/Users/sarsons/Dropbox/wisconsin_women/do/calvin"
}
if $user == 2 {
cd "~/Dropbox/Research/wisconsin_women/data"
global tab = "~/Dropbox/Research/wisconsin_women/draft/tables"
global out = "~/Dropbox/Research/wisconsin_women/out"
global do = "~/Dropbox/Research/wisconsin_women/do"
global RA = "~/Dropbox/Research/wisconsin_women/do/calvin"
}

* Yale colors
global yaleblue = "0 53 107"
global ylb = "40 109 192"
global yo = "189 83 25"
global ylight = "217 233 242"
global graph = "xlabel(,grid glp(dot) glc(gs10) tlc(gs10)) ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"
global graphbar = "ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"


do $do/QJE_R1/preamble_revision.do
replace logsalary = logsalary * 100
	global itt = "i.dist_itt i.dist_itt#i.postexp i.totalexp i.totalexp#i.postexp i.master i.master#i.postexp i.phd i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	global expD = "i.district_code i.district_code#i.postexp i.district_code#i.totalexp i.district_code#i.totalexp#i.postexp i.district_code#i.master i.district_code#i.master#i.postexp i.district_code#i.phd i.district_code#i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	g reltime = year-extension
	g endtime = 1 if reltime==3
	g starttime = 1 if reltime==-3
	bys id: egen fullstart = max(starttime) 
	by id: egen fullend = max(endtime)
	g balanced3 = (fullstart==1&fullend==1)
	drop endtime starttime fullstart fullend	
	g district2010 = district_code if year==2010
	bys id: egen dist_itt = max(district2010)
	drop district2010
	tempvar x
	g `x' = entry == 1 & totalexp == 1 & year <= 2011
	bysort id: egen entry_pre = max(`x')
keep if timex > -6


*-------------------------> 		Appendix file		<-------------------------*

**--> Table A1: Differences by CBA
preserve
	sort district_code year
	merge m:1 district_code year using schoolfinance_new.dta
	drop if _m == 2
	drop _m

	** merge in relevant characteristics: enrollment
	sort district_code year
	merge m:1 district_code year using enrollment.dta
	drop if _m == 2
	drop _m

** create urbanicity
gen suburban = 0
foreach n in 112	2450	413	422	665	721	1015	1092	1253	4970	1414	714	8131	1890	1900	2058	2184	2217	2296	2303	2460	2562	2604	2605	2758	2793	1376	2835	2842	3862	3129	1897	3381	3430	3437	3479	3528	3549	3612	3675	3787	3857	3925	2177	3983	4018	4060	4095	4312	5026	5278	5355	5369	5439	5621	5656	5663	3510	5817	5901	6181	6244	6328	6419	6470 {
replace suburban = 1 if district_code == `n'
}
gen urban = 0
foreach n in 147	8123	8105	8101	1554	1862	2289	2695	2849	3269	3619	3892	4179	4620	8107	5271	5780	8125	6174	6223	6300	8113	8132 {
replace urban = 1 if district_code == `n'
}
	keep if year == 2011
	gen n = 1
	collapse student_count_all tot_exp percent_of_group_black percent_of_group_ec_disadv *urban expire extension pp (sum) n , by(district_code)
	gen exp_pp = tot_exp / (student_count_all * 1000)
	gen exp_beyond = expire > 2011 & expire != .
	gen has_ext = extension > expire & expire != .
	gen ext_beyond = extension > 2011 & expire != .
	replace exp_beyond = . if expire == .
	replace has_ext = . if expire == .
	label var student_count_all "student enrollment"
	label var n "nr of teachers"
	label var exp_pp "per pupil expenditure (\$1,000)"
	label var percent_of_group_black "share black students"
	label var percent_of_group_ec_disadv "share disadvantaged students"
	label var urban "in urban area"
	label var suburban "in suburban area"

	local n = 1
	foreach var of varlist student_count_all n exp_pp percent_of_group_black percent_of_group_ec_disadv *urban {
		di "`var'"
		reg `var' exp_beyond, rob
		matrix A`n' = _b[exp_beyond]
		matrix SDA`n' = _se[exp_beyond]
		matrix PVA`n' = (2 * ttail(e(df_r), abs(_b[exp_beyond]/_se[exp_beyond])))
		matrix NA`n' = e(N)
		reg `var' has_ext, rob
		matrix B`n' = _b[has_ext]
		matrix SDB`n' = _se[has_ext]
		matrix PVB`n' = (2 * ttail(e(df_r), abs(_b[has_ext]/_se[has_ext])))
		matrix NB`n' = e(N)	
		local n = `n' + 1
	}


	matrix table = A1, SDA1, PVA1, B1, SDB1, PVB1, NB1\A2, SDA2, PVA2, B2, SDB2, PVB2, NB2\A3, SDA3, PVA3, B3, SDB3, PVB3, NB3 ///
					\A4, SDA4, PVA4, B4, SDB4, PVB4, NB4\A5, SDA5, PVA5, B5, SDB5, PVB5, NB5\A6, SDA6, PVA6, B6, SDB6, PVB6, NB6 ///
					\A7, SDA7, PVA7, B7, SDB7, PVB7, NB7
	matrix rownames table = "Enrollment" "N teachers" "Per pupil expenditure" "Share black students" ///
							"Share disadvantaged students" "In urban area" "In suburban area"
	matrix colnames table = "Difference" "SE" "P-value"  "Difference" "SE" "P-value" "N" 

	estout matrix(table), mlabels(, none) collabels("Difference" "SE" "P-value" "Difference" "SE" "P-value" "N", lhs("District chars."))
	esttab matrix(table, fmt(3)) using "$tab/decomposition_repl.tex" , replace mlabels(, none) ///
			collabels("Difference" "SE" "P-value" "Difference" "SE" "P-value" "N", lhs("District chars.")) frag
restore



*--> Table A2: Salary pre-Act 10
preserve
	gen D = 0		
	gen E = 0		
	gen T = 0		
	gen S = 0	

	* Pre Act 10	
	eststo r1: reghdfe logsalary female D Y if postexp==0, a(district_code year) cluster(district_code)
	eststo r2: reghdfe logsalary female E D Y if postexp==0, a(district_code totalexp  year) cluster(district_code)	
	eststo r3: reghdfe logsalary female E Ed D Y if postexp==0, a(totalexp phd master district_code  year) cluster(district_code)
	eststo r4: reghdfe logsalary female E Ed T D Y if postexp==0, a(totalexp phd master elem middle high district_code year) cluster(district_code)
	eststo r5: reghdfe logsalary female E Ed T S D Y if postexp==0, a(totalexp phd master elem middle high mathematics english science district_code year) cluster(district_code)

	esttab	r1 r2 r3 r4 r5 using "$tab/salary_change_pre_repl.tex"	///
			, b(3) se(3) unstack nonote label replace se keep(female) ///
			indicate("Distr and year FE = D" "Experience FE = E" "Education FE = Ed" "Grade level FE = T" "Subject = S")  ///		
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) ///
			nomtitle noobs frag substitute(\_ _) ///
			stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
	est clear

* Post Act 10		
	eststo r1: reghdfe logsalary female D Y if postext==1, a(district_code year) cluster(district_code)
	eststo r2: reghdfe logsalary female E D Y if postext==1, a(district_code totalexp  year) cluster(district_code)	
	eststo r3: reghdfe logsalary female E Ed D Y if postext==1, a(totalexp phd master district_code  year) cluster(district_code)
	eststo r4: reghdfe logsalary female E Ed T D Y if postext==1, a(totalexp phd master elem middle high district_code year) cluster(district_code)
	eststo r5: reghdfe logsalary female E Ed T S D Y if postext==1, a(totalexp phd master elem middle high mathematics english science district_code year) cluster(district_code)

	esttab	r1 r2 r3 r4 r5 using "$tab/salary_change_post_repl.tex"	///
			, b(3) se(3) unstack nonote label replace se keep(female) ///
			indicate("Distr and year FE = D" "Experience FE = E" "Education FE = Ed" "Grade level FE = T" "Subject = S")  ///		
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) ///
			nomtitle noobs frag substitute(\_ _) ///
			stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
	est clear		
restore

*--> Table A3: Gender gap, by management gender	- alternative (ITT) definition	
preserve
drop maleprinc malesuper
rename maleprinc_pre maleprinc
rename malesuper_pre malesuper
	gen female_postext_malep = female * postext * maleprinc
	gen postext_malep = postext * maleprinc
	gen female_malep = female * maleprinc
	
	gen female_postext_males = female * postext * malesuper
	gen postext_males = postext * malesuper
	gen female_males = female * malesuper
	capt egen schid = group(district2011 school2011)


	label var maleprinc "Male princ"
	label var malesuper "Male super"
	label var female_malep "Female $\times$ Male princ"
	label var female_males "Female $\times$ Male super"
	label var postext_malep "Post $\times$ Male princ"
	label var postext_males "Post $\times$ Male super"
	label var female_postext_malep "Female $\times$ Male princ $\times$ Post"
	label var female_postext_males "Female $\times$ Male super $\times$ Post"
	global exp_malep = "i.district_code i.maleprinc i.district_code#i.postexp i.totalexp i.maleprinc#i.totalexp i.totalexp#i.postexp i.maleprinc#i.totalexp#i.postexp i.masterup i.maleprinc#i.masterup i.masterup#i.postexp i.maleprinc#i.masterup#i.postexp i.high i.maleprinc#i.high i.high#i.postexp i.maleprinc#i.high#i.postexp i.year i.maleprinc#i.year i.year#i.expire i.maleprinc#i.year#i.expire"
	global exp_males = "i.district_code i.malesuper i.district_code#i.postexp i.totalexp i.malesuper#i.totalexp i.totalexp#i.postexp i.malesuper#i.totalexp#i.postexp i.masterup i.malesuper#i.masterup i.masterup#i.postexp i.malesuper#i.masterup#i.postexp i.high i.malesuper#i.high i.high#i.postexp i.malesuper#i.high#i.postexp i.year i.malesuper#i.year i.year#i.expire i.malesuper#i.year#i.expire"
	eststo r1princ: reghdfe logsalary $tag_exp female female_postext if maleprinc == 1, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r2princ: reghdfe logsalary $tag_exp female female_postext if maleprinc == 0, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r3princ: reghdfe logsalary $tag_exp female female_postext postext_malep maleprinc female_malep female_postext_malep, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r4super: reghdfe logsalary $tag_exp female female_postext if malesuper == 1, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r5super: reghdfe logsalary $tag_exp female female_postext if malesuper == 0, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r6super: reghdfe logsalary $tag_exp female female_postext postext_males malesuper female_males female_postext_males, a($exp i.extension##i.year) vce(cluster district_code)


	esttab	r1princ r2princ r3princ r4super r5super r6super using "$tab/gap_bymanagement_ITT_repl.tex"	///
			, b(3) se(3) unstack nonote label replace se keep(female female_postext female_malep female_postext_malep female_males female_postext_males) ///
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("Principal" "Superintendent", pattern(1 0 0 1 0 0)  ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
			mtitle("Male" "Female" " " "Male" "Female" " ") ///
			indicate("Controls = Edexp" "Yr $\times$ Exp yr = Yr")  ///
			noobs frag substitute(\_ _) ///
			stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
restore





**--> Table A4: Sumstats, by leadership gender
preserve
tempfile temp1
keep if year == 2011
rename male_super_year male_super
rename male_princ_year male_princ
collapse mover_d exit va_s female totalexp master salary_n flfp (min) Min_male_super = male_super (mean) Share_malesuper = male_super, by(district_code)
save `temp1', replace
restore
preserve
tempfile temp2
keep if year == 2011
rename male_super_year male_super
rename male_princ_year male_princ
collapse mover_d exit va_s female totalexp master salary_n flfp (min) Min_male_princ = male_princ (mean) Share_maleprinc = male_princ, by(district_code)
save `temp2', replace
restore

mat R = J(10,6,.)
mat Stars = J(10,6,0)

preserve
use `temp1', clear
sort district_code
merge 1:1 district_code using census.dta
drop _m
replace income = income / 1000
replace salary = salary / 1000
replace Min = 1 - Min
replace Share = 1 - Share
replace flfp = flfp / 100
local j=1
foreach var of varlist female totalexp master va_s  salary_n income sharecollege poverty share_dem flfp {
qui reg `var' Share_malesuper, rob
matrix R[`j', 1] = _b[Share_malesuper]
matrix R[`j', 2] = _se[Share_malesuper]
qui sum `var' if e(sample)
matrix R[`j', 3] = `r(mean)'
matrix Stars[`j', 1] = (abs(_b[Share_malesuper]/_se[Share_malesuper]) > invttail(e(df_r),0.1/2)) ///
+ ///
(abs(_b[Share_malesuper]/_se[Share_malesuper]) > invttail(e(df_r),0.05/2)) + ///
(abs(_b[Share_malesuper]/_se[Share_malesuper]) > invttail(e(df_r),0.01/2))
local j=`j'+1
}
restore

preserve
use `temp2', clear
sort district_code
merge m:1 district_code using census.dta
drop _m
replace income = income / 1000
replace salary = salary / 1000
replace Min = 1 - Min
replace Share = 1 - Share
drop __*
replace flfp = flfp / 100
local j=1
foreach var of varlist female totalexp master va_s  salary_n income sharecollege poverty share_dem flfp {
qui reg `var' Share_maleprinc, rob
matrix R[`j', 4] = _b[Share_maleprinc]
matrix R[`j', 5] = _se[Share_maleprinc]
qui sum `var' if e(sample)
matrix R[`j', 6] = `r(mean)'
matrix Stars[`j', 4] = (abs(_b[Share_maleprinc]/_se[Share_maleprinc]) > invttail(e(df_r),0.1/2)) ///
+ ///
(abs(_b[Share_maleprinc]/_se[Share_maleprinc]) > invttail(e(df_r),0.05/2)) + ///
(abs(_b[Share_maleprinc]/_se[Share_maleprinc]) > invttail(e(df_r),0.01/2))
local j=`j'+1
}
su share_dem
restore

frmttable using "$tab/leadership_gender_balance", statmat(R) substat(2) sdec(3) annotate(Stars)  /// 
asymbol(*,**,***) tex fragment nocenter replace plain ///
ctitles("","Male super","Share of male principals")   ///
rtitles("Share female teachers"\""\""\ ///
"Avg teacher experience"\""\""\ ///
"Share teachers w/Master's"\""\""\ ///
"Value-added"\""\""\ ///
"Salary (\textdollar 1,000)"\""\""\ ///
"Avg income in district (\textdollar 1,000)"\""\""\ ///
"Share w/ college degree in district"\""\""\ ///
"Poverty rate"\""\""\ ///
"Share democratic votes (2012 Presidential)"\""\""\ ///
"Female LFP")


**--> Table A5:  Gender gap, robustness checks
preserve
	reghdfe logsalary $tag_exp female female_postext if inrange(timex,-5,5)&balanced3==1, a($exp i.extension##i.year) vce(cluster district_code)
	est store rob_balance
	reghdfe logsalary $tag_exp female female_postext if entry_pre == 1, a($exp i.extension##i.year) vce(cluster district_code)
	est store rob_entrypre
	reghdfe logsalary $tag_exp female female_postext, a(id $exp i.extension##i.year) vce(cluster district_code)
	est store rob_FE
	reghdfe logsalary $tag_exp female female_postext, a($itt i.extension##i.year) vce(cluster district_code)
	est store rob_itt
	reghdfe logsalary $tag_exp female female_postext, a($expD i.extension##i.year) vce(cluster district_code)
	est store rob_expD
	reghdfe logsalary $tag_exp female female_postext if fte_tot >= 100, a($exp i.extension##i.year) vce(cluster district_code)
	est store rob_fulltime
	reghdfe logsalary $tag_exp female female_postext, a($exp i.extension##i.year Hgrade#Lgrade#postexp) vce(cluster district_code)
	est store rob_grade
		
	esttab	rob_* using "$tab/gap_robust_repl.tex"	///
		, b(3) se(3) unstack nonote label replace se keep(female female_postext female) ///
		obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) ///
		mgroups("Balanced" "Entrants 2007-11" "Teacher FE"  "ITT" "Distr-spec schedule" "Full-time" "Grade FE", pattern(1 1 1 1 1 1 1)  ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
		nomtitle indicate("Controls = Ed" ///
		" Yr $\times$ Exp yr = Yr")		noobs frag substitute(\_ _) ///
		stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
restore



**--> Table A6:  Variance in pay explained by extra duties - using actual data
tempfile X
preserve
use ../../wisconsin_teachers/data/datasets/staff_large_withid.dta, clear
keep if pos != 53
keep id filenumber year pos
duplicates drop
drop if file == .
rename pos otherpos
drop id
rename file id
bysort id year: gen n = _n
egen group = group(id year)
reshape wide otherpos, i(group) j(n)
drop group
sort id year
save `X', replace
restore
drop if id == .
merge 1:1 id year using `X'
gen has_otherpos = _m == 3
drop if _m == 2
drop _m

gen has_otherpos_post = has_otherpos * postext
gen has_female = has_otherpos * female
gen has_female_post = has_female * postext
label var has_otherpos 	"Other duty"
label var has_female	"Female $\times$ Other duty"
label var has_female_post "Female $\times$ Other duty $\times$ Post Ext"
label var has_otherpos_post "Other duty $\times$ Post Ext"

eststo r1: reghdfe logsalary has_otherpos has_otherpos_post Edexp Yr, a($exp i.extension##i.year) cluster(district_code)
eststo r2: reghdfe logsalary has_otherpos has_otherpos_post female female_postext Edexp Yr, a($exp i.extension##i.year) cluster(district_code)
eststo r3: reghdfe logsalary has_otherpos has_otherpos_post female female_postext has_female has_female_post Edexp Yr, a($exp i.extension##i.year) cluster(district_code)

esttab r1 r2 r3 using $tab/otherduty_premium_repl.tex, replace label ///
		keep(has_otherpos has_otherpos_post female female_postext has_female has_female_post) ///
		starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) b(3) se(3) nomtitle noobs frag substitute(\_ _) ///
		indicate("Controls = Yr")  ///		
		stats(N r2, fmt(0 3) labels(`"N"' `"R$^2$"')) 

		
**--> Table A8: Sumstats, by district response
preserve
	use survey.dta, clear
	g n=1
	keep n district_code
	collapse (sum) n, by(district_code)
	tempfile dist_response
	save `dist_response', replace
restore
preserve
use enrollment_school.dta, clear
collapse student_count_all percent_of_group_black percent_of_group_ec_disadv percent_of_group_hisp, by(school_code district_code)
sort school_code district_code
collapse percent_of_group_black percent_of_group_ec_disadv percent_of_group_hisp (sum) student_count_all [aw = student_count_all], by(district_code)
sort district_code
tempfile temp
save `temp', replace
restore
capt rename schoolcode school_code
merge m:1 district_code using  `temp'
	drop if _m==2
	drop _m
	
merge m:1 district_code using  `dist_response'
	drop if _m==2
	g in_survey = (_m==3)
	drop _m
* Estimate district-specific gender gap	
gen gap = .
levelsof district_code, local(D)
qui foreach d of local D {
	noisily disp `d'
	capt reghdfe logsalary female if postext == 1 & district_code == `d', a($exp) 
	capt replace gap = _b[female] if district_code == `d'
	}	
preserve
collapse gap, by(district_code year)
sort district_code year
save gap.dta, replace
restore

sort district_code year
merge m:1 district_code year using gap.dta
drop _m

preserve	
g t=1
bys district_code year: egen teachers = sum(t)
keep if year == 2016
egen tag = tag(school_code district_code)
gen M = male_princ_year if tag == 1
bysort district_code: egen princshare = mean(M)
drop M
collapse (mean) n gap female teachers student_count_all percent_of_group_ec_disadv percent_of_group_hisp percent_of_group_black salary_n totalexp princshare male_super_year expire extension, by(district_code in_survey)
gen has_ext = expire != extension
qui tab expire, gen(Ex)
qui tab extension, gen(Ext)
replace salary_n = salary_n / 1000
replace teachers = teachers / 1000
label variable teachers 			"Nr teachers (hundreds)"
label variable totalexp 			"Avg teacher experience"
label variable salary_n 			"Avg salary (\textdollar 1,000)"
label variable female 				"Share female teachers"
label variable male_super			"Male superintendent"
label variable princshare			"Share principals who are male"
label variable gap 					"Gender pay gap (post-expiration)"
label variable Ext2 				"CBA/extension expires in 2012"
label variable Ext3 				"CBA/extension expires in 2013"
label variable Ext4 				"CBA/extension expires in 2014"
gen resprate = n / teachers
replace resprate = 0 if in_survey == 0
su resprate
global var  teachers salary_n totalexp female gap male_super_year princshare Ext2 Ext3 Ext4
eststo t1: estpost ttest  $var, by(in_survey)
eststo t2: reg in_survey $var, rob
eststo t3: reg resprate $var, rob
esttab t1		using "$tab/ttest_survey_distresponses_rich_repl.tex", noobs nonum ///
				cells("mu_1(fmt(a1)) mu_2(fmt(a1)) b(fmt(a1)star)" ". . se(par)") star(* 0.10 ** 0.05 *** 0.01) ///
				main(mean) aux(sd) nonote unstack label collabels("Represented" "Not Represented" "Diff.")  replace
esttab	t2 t3 using "$tab/survey_distresponses_rich_repl.tex"	///
		, b(4) se(4) unstack nonote label replace se keep($var) ///
		obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("=1 if district has responses" "District response rate", pattern(1 1)  ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
		nomtitle noobs frag substitute(\_ _) ///
		stats(N F, fmt(0 3) labels(`"N"' `"F-stat of joint significance"')) depvars
restore	
	
	


**--> Table A11: Mobility
preserve
gen move_pp = mover_d == 1 & pp == 1 
replace move_pp = . if mover_d == . | pp == .
gen move_ss = mover_d == 1 & pp == 0
replace move_ss = . if mover_d == . | pp == .
gen move_Opp = mover_d == 1 & pp_past == 1 
replace move_Opp = . if mover_d == . | pp_past == .
gen move_Oss = mover_d == 1 & pp_past == 0
replace move_Oss = . if mover_d == . | pp_past == .
gen D =0
gen Y =0
gen X =0
capt rename bachelor ba
eststo r1: reghdfe move_pp female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_pp if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r2: reghdfe move_pp female postext female_postext D Y X if timex > -7 & va_s > 0 & va_s !=  ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_pp if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r3: reghdfe move_pp female postext female_postext D Y X if timex > -7 & va_s <= 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_pp if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'

eststo r4: reghdfe move_ss female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_ss if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r5: reghdfe move_ss female postext female_postext D Y X if timex > -7 & va_s > 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_ss if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r6: reghdfe move_ss female postext female_postext D Y X if timex > -7 & va_s <= 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_ss if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'

eststo r7: reghdfe move_Opp female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_Opp if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r8: reghdfe move_Opp female postext female_postext D Y X if timex > -7 & va_s > 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_Opp if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r9: reghdfe move_Opp female postext female_postext D Y X if timex > -7 & va_s <= 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_Opp if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'

eststo r10: reghdfe move_Oss female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_Oss if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r11: reghdfe move_Oss female postext female_postext D Y X if timex > -7 & va_s > 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_Oss if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'
eststo r12: reghdfe move_Oss female postext female_postext D Y X if timex > -7 & va_s <= 0 & va_s != ., a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
qui sum move_Oss if female == 0 & e(sample)
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 r6 using $tab/mobility_app1_repl.tex, b(4) se(4) unstack nonote label replace se keep(female postext female_postext) ///
		obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("Move to no-schedule" "Move to schedule", pattern(1 0 0 1 0 0)  ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
		mtitle("All teachers" "High VA" "Low VA" "All teachers" "High VA" "Low VA") indicate("District FE = D" "Year FE = Y" "Experience, education FE = X")  ///
		noobs frag substitute(\_ _) stats(N N_clust ymean, fmt(0 0 4) labels(`"N"' `"\# districts"' `"Mean of dep. var."'))

		
esttab r7 r8 r9 r10 r11 r12 using $tab/mobility_app2_repl.tex, b(4) se(4) unstack nonote label replace se keep(female postext female_postext) ///
		obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("Move from no-schedule" "Move from schedule", pattern(1 0 0 1 0 0)  ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
		mtitle("All teachers" "High VA" "Low VA" "All teachers" "High VA" "Low VA") indicate("District FE = D" "Year FE = Y" "Experience, education FE = X")  ///
		noobs frag substitute(\_ _) stats(N N_clust ymean, fmt(0 0 4) labels(`"N"' `"\# districts"' `"Mean of dep. var."'))
restore
		
		
**--> Table A9: Survey, reasons, by super gender
global options "replace label noobs nolines frag nonum nomtitles collabels(none) starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) "
global options2 "replace label noobs nolines frag starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) "
global cells "mu_1(fmt(3))  mu_2(fmt(3)) b(star fmt(3)) se(fmt(3) par)"
use survey.dta, clear
tab age, gen(Age)
label var workinotherind "I worked in other industries"
gen know_neg_yes = regexm(know_neg,"Yes")
label var know_neg_yes "I know someone who negotiated their pay"
gen know_colleague_salary_yes = regexm(know_colleague_salary,"Yes")
label var know_colleague_salary_yes "I know my colleagues' pay"
foreach var in negotiate_prev negotiate_current_beg negotiate_current_after {
gen `var'_yes = regexm(`var',"Yes")
replace `var'_yes = . if regexm(`var',"NA")
}
label var negotiate_prev_yes "w/prev employer"
label var negotiate_current_beg_yes "w/current employer, at start"
label var negotiate_current_after_yes "w/current employer, after start"
foreach var in negotiate_prev negotiate_current_beg negotiate_current_after {
gen `var'_succ = regexm(`var',", success")
replace `var'_succ = . if regexm(`var',"No") | regexm(`var',"NA")
}
label var negotiate_prev_succ " w/prev employer"
label var negotiate_current_beg_succ "w/current employer, at start"
label var negotiate_current_after_succ "w/current employer, after start"
foreach var in noneg_beg noneg_after {
label var `var'_notpossible "it was not possible" 
label var `var'_notcomf "I was not comfortable doing so" 
label var `var'_useless "It was useless"
label var `var'_backlash "I feared backlash"
label var `var'_satisfied "I was satisfied w/pay"
label var `var'_didntknow "I didn't know it was possible"
}
* By Gender principal
preserve
use administrators.dta, clear
keep if position == 51 & year == 2016
rename female female_princ
collapse (max) female_princ, by(district_code)
sort district_code
save temp.dta, replace
restore
sort district
merge m:1 district using temp.dta
drop if _m == 2
drop _m
preserve
use administrators.dta, clear
keep if position == 5 & year == 2016
rename female female_super
collapse (max) female_super, by(district_code)
sort district_code
save temp.dta, replace
restore
sort district
merge m:1 district using temp.dta
drop if _m == 2
drop _m
* People skills
gen conf = regexm(confident_talking,"Yes")
gen sign = regexm(subtle_signals,"Agree")
gen feel = regexm(read_feelings,"Agree")
gen ppl = regexm(people_skills,"Agree")
gen perf = regexm(rate_perf,"Above")
replace perf = regexm(rate_perf,"Average")
label var conf "I am confident talking to people I don't know"
label var sign "I can read subtle signals"
label var feel "I can read people's feelings"
label var ppl "I have good people's skills"
label var perf "My performance is above the mean"
label var gender "Female"
gen D = 0
gen fem_femsuper = gender * female_super
label var female_super "Female super"
label var fem_femsuper "Female * F super"

replace perf = regexm(rate_perf,"Average")
label var conf "I am confident talking to people I don't know"
label var sign "I can read subtle signals"
label var feel "I can read people's feelings"
label var ppl "I have good people's skills"
label var perf "My performance is above the mean"

qui reg gender negotiate_prev_yes negotiate_current_beg_yes negotiate_current_after_yes /// 
		likelihood* Age* conf sign feel ppl perf workinother know_*_yes
gen sample = e(sample)		



* regs
preserve
keep if negotiate_current_after_yes == 0
eststo r4: areg noneg_after_notpossible gender fem_femsuper $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_notpossible if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: areg noneg_after_notcomf gender fem_femsuper $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_notcomf if gender == 0
estadd scalar ymean = `r(mean)'
eststo r6: areg noneg_after_useless gender fem_femsuper $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_useless if gender == 0
estadd scalar ymean = `r(mean)'
eststo r7: areg noneg_after_backlash gender fem_femsuper $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_backlash if gender == 0
estadd scalar ymean = `r(mean)'
eststo r8: areg noneg_after_satisfied gender fem_femsuper $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_satisfied if gender == 0
estadd scalar ymean = `r(mean)'
restore
esttab r4 r5 r6 r7 r8  using "$tab/survey_reg_reasons_gender_repl.tex", b(3) se(3) keep(gender fem_femsuper) $options2 ///
		indicate("Controls = conf") ///
		mgroups("Reasons for not negotiating", pattern(1 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) stats(N ymean, fmt(0 3) ///
		labels(`"N"' `"Y mean, males"')) mtitle( "Not possible" "Not comfortable" "Useless" "Fear backlash" "Satisfied w/pay")

	


*--> Table A10: Survey, Heterogeneity by people skills, knnowledge of salaries, confidence
rename negotiate_current_beg_yes negot_beg
rename negotiate_current_after_yes negot_after

gen Know = regexm(know_colleague_salary,"Yes")
replace Know = . if know_colleague_salary == ""
gen People = regexm(people,"Agree")
replace People = . if people == ""
gen Feel = regexm(read,"Agree")
replace Feel = . if read == ""
gen Signals = regexm(subtle,"Agree")
replace Signals = . if subtle == ""
gen Aboveavg = regexm(rate_perf,"Above")
replace Aboveavg = . if rate_perf == ""
gen Talk = regexm(confident_talking,"Yes")
replace Talk = . if confident_talking == ""


gen gender_K = gender * Know
label var Know "Knows colleague pay"
label var gender_K "Female $\times$ knows colleague pay"

eststo r1: reg negot_beg gender Know gender_K, cluster(district_code)
qui sum negot_beg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r2: reg negot_after gender Know gender_K, cluster(district_code)
qui sum negot_after if gender == 0
estadd scalar ymean = `r(mean)'
eststo r3: reg likelihood_salary_neg gender Know gender_K, cluster(district_code)
qui sum likelihood_salary_neg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r4: reg negotiate_current_beg_succ gender Know gender_K, cluster(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: reg noneg_beg_notcomf gender Know gender_K, cluster(district_code)
qui sum noneg_beg_notcomf if gender == 0
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 using "$tab/survey_knowledge_tab_repl.tex", b(3) se(3) drop(_cons) $options nogaps

gen gender_P = gender * People
label var People "People skills"
label var gender_P "Female $\times$ People skills"

eststo r1: reg negot_beg gender People gender_P, cluster(district_code)
qui sum negot_beg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r2: reg negot_after gender People gender_P, cluster(district_code)
qui sum negot_after if gender == 0
estadd scalar ymean = `r(mean)'
eststo r3: reg likelihood_salary_neg gender People gender_P, cluster(district_code)
qui sum likelihood_salary_neg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r4: reg negotiate_current_beg_succ gender People gender_P, cluster(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: reg noneg_beg_notcomf gender People gender_P, cluster(district_code)
qui sum noneg_beg_notcomf if gender == 0
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 using "$tab/survey_people_tab_repl.tex", b(3) se(3) drop(_cons) $options nogaps

gen gender_T = gender * Talk
label var Talk "Confident talking"
label var gender_T "Female $\times$ Confident talking"

eststo r1: reg negot_beg gender Talk gender_T, cluster(district_code)
qui sum negot_beg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r2: reg negot_after gender Talk gender_T, cluster(district_code)
qui sum negot_after if gender == 0
estadd scalar ymean = `r(mean)'
eststo r3: reg likelihood_salary_neg gender Talk gender_T, cluster(district_code)
qui sum likelihood_salary_neg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r4: reg negotiate_current_beg_succ gender Talk gender_T, cluster(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: reg noneg_beg_notcomf gender Talk gender_T, cluster(district_code)
qui sum noneg_beg_notcomf if gender == 0
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 using "$tab/survey_talk_tab_repl.tex", b(3) se(3) drop(_cons) $options nogaps
		
gen gender_F = gender * Feel
label var Feel "Understand feelings"
label var gender_F "Female $\times$ Understand feelings"

eststo r1: reg negot_beg gender Feel gender_F, cluster(district_code)
qui sum negot_beg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r2: reg negot_after gender Feel gender_F, cluster(district_code)
qui sum negot_after if gender == 0
estadd scalar ymean = `r(mean)'
eststo r3: reg likelihood_salary_neg gender Feel gender_F, cluster(district_code)
qui sum likelihood_salary_neg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r4: reg negotiate_current_beg_succ gender Feel gender_F, cluster(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: reg noneg_beg_notcomf gender Feel gender_F, cluster(district_code)
qui sum noneg_beg_notcomf if gender == 0
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 using "$tab/survey_feel_tab_repl.tex", b(3) se(3) drop(_cons) $options nogaps
		
gen gender_A = gender * Above
label var Above "Perf $>$ avg"
label var gender_A "Female $\times$ Perf $>$ avg"

eststo r1: reg negot_beg gender Above gender_A, cluster(district_code)
qui sum negot_beg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r2: reg negot_after gender Above gender_A, cluster(district_code)
qui sum negot_after if gender == 0
estadd scalar ymean = `r(mean)'
eststo r3: reg likelihood_salary_neg gender Above gender_A, cluster(district_code)
qui sum likelihood_salary_neg if gender == 0
estadd scalar ymean = `r(mean)'
eststo r4: reg negotiate_current_beg_succ gender Above gender_A, cluster(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: reg noneg_beg_notcomf gender Above gender_A, cluster(district_code)
qui sum noneg_beg_notcomf if gender == 0
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 using "$tab/survey_conf_tab_repl.tex", b(3) se(3) drop(_cons) $options ///
		stats(N ymean, fmt(0 3) ///
		labels(`"N"' `"Y mean, males"')) nogaps
		



